package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.DefaultListModel;
import javax.swing.JScrollBar;
import javax.swing.JTable;
import javax.swing.JList;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JScrollPane;

public class LogGUI extends JFrame {

	private JPanel contentPane;
	private JList list;
	private boolean bisOpeenedWindow;
	 DefaultListModel listModel;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LogGUI frame = new LogGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LogGUI() {
		bisOpeenedWindow = true;
		this.setVisible(true);
		BuildGui();
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		
		this.addWindowListener(new WindowAdapter()
		{
		      public void windowClosing(WindowEvent e)
		      {
		          exitProcedure();
		      }
		});
		
	}
	
	//method takes care of not disposing the JFRAME log
	private void exitProcedure(){
		
		this.setVisible(false);
		this.bisOpeenedWindow=false;
		
	}
	public void CloseWindow(){
		exitProcedure();
	}
	// return Log window status
	public boolean getWindowStatus(){
		return bisOpeenedWindow;
	}
	
	private void BuildGui(){
		
		setBounds(100, 100, 450, 354);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		  listModel = new DefaultListModel();  
		 list = new JList(listModel);
		list.setBounds(60, 58, 368, 247);
	//	list.add(new JScrollBar());
		JScrollPane scrollPne = new JScrollPane(list);
		
		//contentPane.add(scrollPne);
		contentPane.add(list);
		
		JLabel lblLog = new JLabel("Log:");
		lblLog.setFont(new Font("Tahoma", Font.PLAIN, 18));
		lblLog.setBounds(50, 25, 69, 22);
		contentPane.add(lblLog);
	}
	
	public void add2Log(String errormsg){
		//list.add(errormsg);
	//	JLabel lbl= new JLabel(errormsg);
		listModel.addElement(errormsg);
		list.revalidate();
		//list.add(lbl);
		
	}
}

